import { request } from '@inbiz/utils';
const version = InbizConfig.API_VERSION

// 根据appId获取应用列表
export async function getAppList(params: {}, appId: string) {
  return request(`/inbiz/api/services/engines/v${version}/app/${appId}`, {
    params,
  });
}

// 通过应用ID获取菜单
export async function getMenuTree(params: {
  siteOutId: string;
  parentOutId: string;
}) {
  return request(`/inbiz/api/services/front/engines/v${version}/menu/PermTreeList`, {
    params,
  });
}

// 通过菜单ID获取权限
export async function getPermissionList(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuPerm`, {
    params,
  });
}

// 添加权限
export async function postPermission(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuPerm`, {
    method: 'POST',
    data: params,
  });
}

// 修改权限
export async function putPermission({ params, data }: any) {
  return request(
    `/inbiz/api/services/front/engines/v${version}/menuPerm?entityId=${params.entityId}`,
    {
      method: 'PUT',
      data: data,
    },
  );
}

// 删除权限
export async function deletePermission(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuPerm`, {
    method: 'DELETE',
    data: params,
  });
}

// 站点下获取配置
export async function getOnlineTree(params: any) {
  return request(
    `/inbiz/api/services/front/engines/v${version}/menuRelation/OnlineTree`,
    {
      params: params,
    },
  );
}

//根据菜单outid获取模型和模型下的字段信息
export async function getModelParamList(params: any) {
  return request(
    `/inbiz/api/services/engines/v${version}/menuRelation/modelParamList`,
    {
      params: params,
    },
  );
}

//获取菜单按钮的权限 用户分配列表
export async function getMenuButtonPerm(params: any) {
  return request(`/inbiz/api/services/engines/v${version}/menuButtonPerm`, {
    params: params,
  });
}

//新增菜单按钮权限
export async function addMenuButtonPerm(params: any) {
  return request(`/inbiz/api/services/engines/v${version}/menuButtonPerm`, {
    method: 'POST',
    data: params,
  });
}

//修改菜单按钮权限
export async function editMenuButtonPerm({ params, data }: any) {
  return request(`/inbiz/api/services/engines/v${version}/menuButtonPerm`, {
    method: 'PUT',
    params,
    data,
  });
}

//删除菜单按钮权限
export async function delMenuButtonPerm(params: any) {
  return request(`/inbiz/api/services/engines/v${version}/menuButtonPerm`, {
    method: 'DELETE',
    data: params,
  });
}

// 新增菜单模型权限
export async function addModelPerm(params: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/modelPerm`, {
    method: 'POST',
    data: params,
  });
}

// 修改菜单模型权限
export async function editModelPerm({ params, data }: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/modelPerm`, {
    method: 'PUT',
    params,
    data,
  });
}

// 删除菜单模型权限
export async function delModelPerm(params: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/modelPerm`, {
    method: 'DELETE',
    data: params,
  });
}
//根据用户获取某个应用下的菜单权限信息
export async function getMenuUserPerm(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuUserPerm`, {
    params: params,
  });
}
//用户新增菜单权限
export async function addMenuUserPerm(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuUserPerm`, {
    data: params,
    method: 'POST',
  });
}
//用户删除菜单权限
export async function delMenuUserPerm(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuUserPerm`, {
    params: params,
    method: 'DELETE',
  });
}
//根据用户获取某个应用下的菜单权限信息
export async function getButtonUserPerm(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuUserButtonPerm`, {
    params: params,
  });
}
//用户新增菜单权限
export async function addButtonUserPerm(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuUserButtonPerm`, {
    data: params,
    method: 'POST',
  });
}
//用户删除菜单权限
export async function delButtonUserPerm(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/menuUserButtonPerm`, {
    data: params,
    method: 'DELETE',
  });
}
//根据用户获取某个应用下的菜单权限信息
export async function getModelUserPerm(params: any) {
  return request(`/inbiz/api/services/engines/v${version}/menuUserModelPerm`, {
    params: params,
  });
}

//获取当前站点下的模型分组
export async function getModule(params: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/module`, {
    params: params,
    method: 'GET',
  });
}

// 根据模块获取模型
export async function getModel(params: any) {
  return request(`/inbiz/api/services/modelengine/v${version}/model`, {
    params: params,
    method: 'GET',
  });
}

//获取菜单模型字段的权限 用户分配列表
export async function getModelPerm(params: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/modelPerm`, {
    params: params,
    method: 'GET',
  });
}

//根据用户获取模型的字段权限
export async function getUserModelPerm(params: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/userModelPerm`, {
    params: params,
    method: 'GET',
  });
}
//用户新增模型权限
export async function addModelUserPerm(params: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/userModelPerm`, {
    data: params,
    method: 'POST',
  });
}
//用户删除模型权限
export async function delModelUserPerm(params: any) {
  return request(`/inbiz/api/services/front/modelengine/v${version}/userModelPerm`, {
    data: params,
    method: 'DELETE',
  });
}
// 获取应用设置
export async function getSettings(appId: string) {
  return request(
    `/inbiz/api/services/engines/v${version}/app/${appId}/settings`,
    {
      method: 'GET',
    },
  );
}

//获取数据权限模块列表数据
export async function getDPModule() {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermModule`, {
    method: 'GET',
  });
}

//用户新增/编辑数据权限模块
export async function updateDPModule(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermModule`, {
    data: params,
    method: 'POST',
  });
}

// 删除数据权限模块
export async function deleteDataPermModule(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermModule`, {
    method: 'delete',
    params,
  });
}

// 权限列表
export async function getDataPermRule(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermRule/pageList`, {
    params,
  });
}

// 获取查询器列表
export async function getModelQuery(params: any = {}) {
  const { appId, ...agms } = params;
  return request(`/inbiz/api/services/modelengine/v${version}/moduleQuery/byAppId`, {
    params: agms,
  });
}

// 获取模型列表
export async function getModelList(params: any = {}) {
  const { appId, ...agms } = params;
  return request(`/inbiz/api/services/modelengine/v${version}/model/manys/${appId}`, {
    params: agms,
  });
}

// 创建权限
export async function postDataPermRule(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermRule`, {
    method: 'post',
    data: params,
  });
}

// 修改权限
export async function putDataPermRule(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermRule`, {
    method: 'put',
    data: params,
  });
}

// 删除规则列表
export async function deleteDataPermRule(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermRule`, {
    method: 'delete',
    params
  })
}

// 启用停用
export async function statusChange(params: any) {
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermRule/statusChange`, {
    method: 'post',
    data: params
  })
}

// 获取规则详情
export async function getRuleDetail(params: any) {
  const { id } = params;
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermRule/${id}/ruleDetail`)
}

// 获取规则详情
export async function getPermMemberDetail(params: any) {
  const { id } = params;
  return request(`/inbiz/api/services/front/engines/v${version}/dataPermRule/${id}/permMemberDetail`)
}

// 根据模型id获取字段列表
export async function getModelFieldList(params: any) {
  return request(`/inbiz/api/services/modelengine/v${version}/model/fields`, {
    method: 'GET',
    params
  })
}

// 根据查询器key获取字段列表
export async function getQueryFieldList(params: any) {
  return request(`/inbiz/api/services/modelengine/v${version}/modelQueryAdapter/controlField`, {
    params
  })
}